#!/bin/sh
#Barry Kauler 2006 www.puppylinux.com
#2007 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)

#exec &> /tmp/umount.log

[ ! $1 ] && exec umount-FULL

#remove everything except the device or mntpt...
LASTPARAM="`echo -n "$*" | tr '\t' ' ' | tr -s ' ' | tr ' ' '\n' | grep '^/'`"

if [ "$LASTPARAM" != "" ] ; then
	if [ -b "$1" ] ; then
		# block device
		DEVNAME=$(basename "$LASTPARAM")
	else
		# mountpoint
		DEVNAME=$(mount-FULL -v | grep " $LASTPARAM " | cut -f 1 -d " ")
		DEVNAME=$(basename "$DEVNAME")
	fi
fi

umount-FULL -d "$@" #-d = free loop device
RETVAL=$?

if [ -z "$DEVNAME" -o ! -b /dev/${DEVNAME} ] ; then
	exit $RETVAL
fi

if [ $RETVAL -eq 0 ] ; then
	if [ -f /usr/local/pup_event/frontend_funcs ] ; then
		#ROX: create or refresh desktop icon
		/usr/local/pup_event/frontend_funcs rox_umount "$DEVNAME"
	fi
fi

#v409, instead just make sure the symlink stays there...
if [ ! -L /etc/mtab ];then
 rm -f /etc/mtab
 ln -s /proc/mounts /etc/mtab
fi

exit $RETVAL
